<!--# layout("/common/layout.html",{"jsBase":"/js/atnm/atnmStatement/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data" lay-filter="editform">
    <input type="hidden" name="mainId" id="mainId">

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">自荐信标题</label>
                <div class="layui-input-inline" style="width:512px">
                    <input type="text" name="headline" id="headline" autocomplete="off" maxlength="50"
                           class="layui-input" lay-verify="required">
                </div>
            </div>

        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">年份</label>
                <div class="layui-input-inline">
                    <input type="text" name="year" id="year" autocomplete="off" maxlength="4" class="layui-input"
                           lay-verify="required|number">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">大学</label>
                <div class="layui-input-inline" id="univId">

                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">对应专业</label>
                <div class="layui-input-inline">
                    <input type="text" name="majorName" id="majorName" autocomplete="off" maxlength="50"
                           class="layui-input">
                </div>
            </div>
        </div><!--form item-->
    </div><!--row-->
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">要求</label>
                <div class="layui-input-block" style="width:780px">
                    <textarea name="require" id="require" placeholder="请输入" class="layui-textarea"
                              lay-verify="required" rows="4"></textarea>
                </div>
            </div>

        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">免费内容</label>
                <div class="layui-input-block" style="width:780px">
                    <textarea name="freeTrial" id="freeTrial" placeholder="请输入" class="layui-textarea"
                              lay-verify="required" rows="8"></textarea>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">正文</label>
                <div class="layui-input-block" style="width:780px">
                    <textarea name="mainBody" id="mainBody" placeholder="请输入" class="layui-textarea"
                              lay-verify="required" rows="10"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">全文字数</label>
                <div class="layui-input-inline">
                    <input type="text" name="wordCount" id="wordCount" autocomplete="off" maxlength="50"
                           class="layui-input" lay-verify="required|number">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">剩余字数</label>
                <div class="layui-input-inline">
                    <input type="text" name="remainWord" id="remainWord" autocomplete="off" maxlength="10"
                           class="layui-input" lay-verify="required|number">
                </div>
            </div>
        </div>
    </div>

    <layui:singleFile id="wordUrl" tagName="word" tips="不超过5Mword"/>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">是否免费</label>
                <div class="layui-input-inline">
                    <input type="radio" name="isFree" value="1" title="是">
                    <input type="radio" name="isFree" value="0" title="否" checked>

                </div>
            </div>
        </div>
    </div>
    <layui:submitButtons id="addButton"/>
</form>
<!--#} -->
<script>
    layui.extend({
        loading: '../../../plugins/layui_extends/loading/loading',
        selectN: '../../../plugins/layui_extends/selectN',
    }).define(['form', 'laydate', 'table', 'selectN','loading', 'atnmStatementApi'], function (exports) {
        var form = layui.form;
        var atnmStatementApi = layui.atnmStatementApi;
        var index = layui.index;
        var isNew = true;
        var selectN = layui.selectN;
        <!--# if(!(isEmpty(atnmStatementJson))){  -->
        isNew = false;
        <!--# } -->
        var view = {
            init: function () {
                Lib.initGenrealForm($("#addForm"), form);
                this.initSubmit();
                var selectUniv = selectN({
                    //元素容器【必填】
                    elem: '#univId'

                    //候选数据【必填】
                    ,data: "univList.json"

                    //默认值
                    ,selected: [${atnmStatement.univId!}]
                    ,search: true
                    //input的name 不设置与选择器相同(去#.)
                    ,name: 'univId'
                    //候选项数据的键名
                    ,field: {idName:'univId',titleName:'univName'}
                });
            },
            initSubmit: function () {
                $("#addButton").click(function () {
                    $("#addButton").hide();
                    $("#addButton-loading").show();
                    $("#addButton-loading").loading();
                    form.on('submit(form)', function () {
                        atnmStatementApi.saveForm(isNew, $('#addForm'), function () {
                            parent.window.dataReload();
                            Common.info("保存成功");
                            Lib.closeFrame();
                        });
                    });
                });

                $("#addButton-cancel").click(function () {
                    Lib.closeFrame();
                });
            }

        }
        view.init();
        <!--# if(!(isEmpty(atnmStatementJson))){  -->
        var formJson = ${atnmStatementJson};
        form.val("editform", formJson);
        $(".file_link").each(function () {
            var a = document.createElement('a');
            var aJq = $(a);
            aJq.html("下载文件");
            aJq.attr("href", formJson[$(this).attr("id")]);
            aJq.attr("target", "_blank");
            $(this).append(aJq);
        });
        <!--# } -->
    });
</script>
